home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / chi_sqr.pro < prev    next >
Text File  |  1997-07-08  |  1KB  |  61 lines

  1. ; $Id: chi_sqr.pro,v 1.2 1997/01/15 04:02:19 ali Exp $
  2. ;
  3. ;  Copyright (c) 1991-1997, Research Systems Inc.  All rights
  4. ;  reserved. Unauthorized reproduction prohibited.
  5.  
  6.  
  7. function chi_sqr, a,DF 
  8. ;+
  9. ; NAME:
  10. ;    CHI_SQR
  11. ;
  12. ; PURPOSE: 
  13. ;    CHI_SQR returns the cutoff value v such that
  14. ;
  15. ;        Probability(X > v) = a
  16. ;
  17. ;    where X is a random variable from the chi_sqr distribution with 
  18. ;    v degrees of freedom. 
  19. ;
  20. ; CATEGORY:
  21. ;    Statistics.
  22. ; CALLING SEQUENCE:
  23. ;    Result = CHI_SQR(A, DF)
  24. ;
  25. ; INPUT:
  26. ;    A:    probability
  27. ;    DF:    degrees of freedom
  28. ;
  29. ; OUTPUT:
  30. ;    If a is between 0 and 1, then the cutoff value is returned.
  31. ;    Otherwise, -1 is returned to indicate an error.
  32. ;-
  33. if (a gt 1 or a lt 0) then return,-1  
  34. if a eq 0 THEN return, 1.e12
  35. if a eq 1 THEn return,0
  36.  
  37. if DF lt 0 THEN BEGIN
  38.   print,'chi_sqr-- degrees of freedom must be nonegative'
  39.   return, -1
  40. ENDIF
  41. case 1 of
  42.  DF EQ 1: UP=300.0 
  43.  DF EQ 2: UP =100.0 
  44.  DF GT 2 and  DF LE 5: UP=30.0
  45.  DF GT 5 and DF LE 14: UP = 20.0
  46.  ELSE: UP = 12.0
  47. ENDCASE
  48.  
  49. Below=0
  50.  
  51.  while chi_sqr1(UP,DF) LT 1- a DO BEGIN
  52.       Below = UP
  53.       UP = 2*UP
  54.  ENDWHILE
  55.  
  56.  
  57. return, pd_bisection([1-a,DF],'chi_sqr1',Up,Below)
  58. end
  59.  
  60.